package com.test.controller.uc;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.test.entity.uc.Person;
import com.test.service.uc.PersonService;

@Controller("personController")
@RequestMapping("/person")
public class PersonController {
	
	@Resource(name="personService")
	private PersonService personService;

	@RequestMapping(value="/getPersonById/{id}")
	public @ResponseBody Map<String,Object> testIndex(@PathVariable("id") String id){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		return map;
	}
	
	@RequestMapping(value="toLogin")
	public ModelAndView toLogin(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("login");
		return mv;
	}
	
	@RequestMapping(value="checkHasPerson")
	public @ResponseBody Map<String,Object> checkHasPerson(){
		Map<String,Object> map = new HashMap<String,Object>();
		Boolean hasPerson = personService.hasPerson();
		map.put("state", hasPerson);
		return map;
	}
	
	 @RequestMapping(value="addPerson")
	 public void addPerson(){
		 Person person = new Person();
		 person.setAge(12);
		 person.setId("b");
		 person.setName("aa");
		 
		 personService.addPerson(person);
	 }
}
